package gwtI18nEditor.widgets;

import gwtI18nEditor.datamodel.Message;
import gwtI18nEditor.datamodel.MessageType;
import gwtI18nEditor.datamodel.Translation;
import gwtI18nEditor.resources.EscapeTable;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class DefaultTranslationViewer extends JScrollPane {
	
	private JTextArea   editor;

	public DefaultTranslationViewer() {
		super();
		editor = new JTextArea();
		editor.setEditable(false);
		editor.setWrapStyleWord(true);
		editor.setLineWrap(true);
		setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		setViewportView(editor);
	}
	
	public void updateEditor(Message message) {
		for (Translation translation: message.getTranslations())
			if (translation.getLocale()==null) 
				editor.setText(EscapeTable.unescape(translation.getMessage(), message.getType()==MessageType.SAFEHTML));
	}
}
